package io.cloud.tec.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.pattern.PathPatternParser;

import java.util.Objects;


/**
 * 参考：https://blog.csdn.net/qq_43842093/article/details/117770358
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 配置大小写敏感
     * 参考：https://blog.csdn.net/f641385712/article/details/118031407
     *
     * @param configurer
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        PathPatternParser patternParser = configurer.getPatternParser();
        if (Objects.isNull(patternParser)) {
            patternParser = new PathPatternParser();
            configurer.setPatternParser(patternParser);
        }
        patternParser.setCaseSensitive(false);

        PathMatcher pathMatcher = configurer.getPathMatcher();
        if (Objects.isNull(pathMatcher)) {
            pathMatcher = new AntPathMatcher();
            configurer.setPathMatcher(pathMatcher);
        }

        if (pathMatcher instanceof AntPathMatcher) {
            ((AntPathMatcher) pathMatcher).setCaseSensitive(false);
        }

//        if (this.mvcProperties.getPathmatch()
//                .getMatchingStrategy() == WebMvcProperties.MatchingStrategy.PATH_PATTERN_PARSER) {
//            configurer.setPatternParser(pathPatternParser);
//        }
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/web/**","/build/**").addResourceLocations("classpath:/pdf.js/web/","classpath:/pdf.js/build/");
    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        HandlerInterceptor interceptor = new HandlerInterceptor() {
//        };
//        registry.addInterceptor(interceptor).addPathPatterns("/pdf.js/build/", "/pdf.js/web/");
//    }
}
